<?php include 'header.php'; ?>
		<?php if(!isset($_SESSION['user'])):  ?>
			<meta http-equiv="refresh" content="0;URL=index.php">
		<?php else:?>
		<br><br><a href = "newAbstract.php" class="button"> New Abstract </a></br><br><br><br>
		<?php 
			if (in_array($_SESSION['user'], $admins)) { //If the user is logged in as an administrator
				if($_SESSION['user'] === "mikler")
					{
							echo "<h2>Add a new administrator</h2>";
						?>
							<form action="addAdmin.php" method="get">
								Enter the username for the new Administrator: <input type="text" name="admin">
								<input type="submit"><br><br>
							</form>
						<?php
						
						echo "<h2>Current Admins</h2>";
						$query = "SELECT username from admins";
						$result = mysqli_query($con, $query);
						echo "<table class='hoverTable'>
							<tr><th>Admin Name</th>
							<th>Delete</th></tr>";
						
						while ($row = mysqli_fetch_array($result)) {
							echo "<tr><td>" . $row['username'] . "</td>";
							echo "<td><a href = 'deleteAdmin.php?admin=" . $row['username'] . "'><img src='images/trashbin.png' height=24px width=24px></a></td></tr>";
						}
						
						echo "</table><br><br>";
					}
				echo "<h2>Add a new reviewer</h2>";
				?>
					<form action="addReviewer.php" method="get">
						Enter the username for the new reviewer: <input type="text" name="reviewer">
						<input type="submit"><br><br>
					</form>
				<?php
				
				echo "<h2>Current Reviewers</h2>";
				$query = "SELECT username from reviewers";
				$result = mysqli_query($con, $query);
				echo "<table class='hoverTable'>
					<tr><th>Reviewer Name</th>
					<th>Delete</th></tr>";
				
				while ($row = mysqli_fetch_array($result)) {
					echo "<tr><td>" . $row['username'] . "</td>";
					echo "<td><a href = 'deleteReviewer.php?reviewer=" . $row['username'] . "'><img src='images/trashbin.png' height=24px width=24px></a></td></tr>";
				}
				
				echo "</table><br><br>";
			}
			else if (in_array($_SESSION['user'], $reviewers)){ //If the user is logged in as a reviewer
				echo '<a href = "searchAbstracts.php" class="button"> Search Abstracts </a></br><br><br><br>';
			}
			
			echo "<h2>Your Previously Submitted Abstracts</h2><br>";
			
			$query = "SELECT abstractID, link, first_name, last_name, dept_name, univ_name, title, username, submit_date, uploadedAbstractID FROM author natural join abstract WHERE username = '" . $_SESSION['user'] . "' order by submit_date DESC";
			$result = mysqli_query($con, $query); ?>
			
			<table class="hoverTable">
				<tr>
						<th><a href = '#' onclick='fillHiddenField("submit_date"); return false;'>Submission Date</a></th>
						<th>Title</th>
						<th>Download Abstract</td>
						<th>Full Dissertation</th>
						<th>Delete</th></tr>
			<?php 
				while ($row = mysqli_fetch_array($result)){
					echo "<tr><td>" . date('m/j/Y', strtotime($row['submit_date'])) .
						"</td><td>" . "<a href = displaySearch.php?search=" . $row['username'] . "&ID=" . $row['abstractID'] . ">" . $row['title'] . "</a>" . "</td>" .
						"</td><td>";
						if($row['uploadedAbstractID'] > 0)
							echo "<a href = getFile.php?id=" . $row['uploadedAbstractID'] . "><img src='images/download-icon.png' height=24px width=24px></a></td>"; 
						else
							echo "<img src='images/red-x.png' height=24px width=24px></td>";
						if (!empty($row['link']))
							echo "</td><td><a href = " . $row['link'] . " target='_blank'><img src='images/linkicon.png' height=24px width=24px></a></td>";
						else
							echo "</td><td><img src='images/red-x.png' height=24px width=24px></td>";
						echo "<td><a href = deleteAbstract.php?abstract=" . $row['abstractID'] . "><img src='images/trashbin.png' height=24px width=24px></a></td></tr>";
				}
				echo "</table>";
					?>
		<?php endif; ?>
<?php include 'footer.php'; ?>